package com.kirayous.api.blog.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kirayous.common.dto.CategoryBackDTO;
import com.kirayous.common.dto.CategoryDTO;
import com.kirayous.common.entity.Category;
import com.kirayous.common.vo.ConditionVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author KiraYous
 * @since 2021-09-23
 */
@Mapper
public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 查询分类和对应文章数量
     *
     * @return {@link List<CategoryDTO>}分类列表
     */
    @Select("    SELECT\n" +
            "    c.id,\n" +
            "    c.category_name,\n" +
            "    COUNT( a.id ) AS article_count\n" +
            "    FROM\n" +
            "    tb_category c\n" +
            "    LEFT JOIN tb_article a ON c.id = a.category_id\n" +
            "    GROUP BY\n" +
            "    c.id")
    List<CategoryDTO> listCategoryDTO();

    /**
     * 查询后台分类列表
     *
     * @param current   页码
     * @param size      大小
     * @param condition 条件
     * @return {@link List<CategoryBackDTO>} 分类列表
     */
    List<CategoryBackDTO> listCategoryBackDTO(@Param("current") Long current, @Param("size") Long size, @Param("condition") ConditionVO condition);

}
